//
//  LoginController.m
//  steamRoom
//
//  Created by 安建伟 on 2019/7/6.
//  Copyright © 2019 com.thingcom. All rights reserved.
//

#import "LoginViewController.h"
#import "MyDeviceViewController.h"
#import "MainViewController.h"

@interface LoginViewController () <UITextFieldDelegate,GizWifiSDKDelegate>

@property (strong, nonatomic) dispatch_source_t timer;
@property (strong, nonatomic) UIView *headerView;
@property (strong, nonatomic) UIButton *loginBtn1;//页面切换按钮
@property (strong, nonatomic) UIButton *registerBtn1;//页面切换按钮
@property (strong, nonatomic) UIButton *forgetPWBtn1;//页面切换按钮

@property (strong, nonatomic) UIView *loginView;
@property (strong, nonatomic) UIView *registerView;
@property (strong, nonatomic) UIView *forgetPWView;

@property (strong, nonatomic) UITextField *phoneTF;
@property (strong, nonatomic) UITextField *phoneLogTF;
@property (strong, nonatomic) UITextField *phoneRegTF;
@property (strong, nonatomic) UITextField *passwordLogTF;
@property (strong, nonatomic) UITextField *passwordRegTF;
@property (strong, nonatomic) UITextField *forgetPWTF;
@property (strong, nonatomic) UITextField *verifyRegTF;
@property (strong, nonatomic) UITextField *verifyTF;
@property (strong, nonatomic) UITextField *passwordRegConTF;
@property (strong, nonatomic) UITextField *passwordConTF;
@property (strong, nonatomic) UIButton *verifyRegBtn;
@property (strong, nonatomic) UIButton *verifyforgetBtn;

@property (strong, nonatomic) UIButton *loginBtn;
@property (strong, nonatomic) UIButton *registerBtn;
//@property (strong, nonatomic) UIButton *passwordVisiableBtn;
@property (strong, nonatomic) UIButton *forgetPWBtn;
@property (strong, nonatomic) UIButton *forgetSureBtn;
@property (strong, nonatomic) UIButton *forgetBackBtn;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.layer.backgroundColor = [UIColor colorWithRed:250/255.0 green:250/255.0 blue:250/255.0 alpha:1].CGColor;
    _headerView = [self headerView];
    _loginView = [self loginView];
    _registerView = [self registerView];
    _forgetPWView = [self forgetPWView];
    
    [GizWifiSDK sharedInstance].delegate = self;
    [self autoLogin];
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = YES;
    
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.translucent = NO;
    
}

#pragma mark - Lazy load

-(UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 220.f)];
        [self.view addSubview:_headerView];
        UIImageView *bgImg = [[UIImageView alloc] initWithFrame:_headerView.bounds];
        [bgImg setImage:[UIImage imageNamed:@"head_background"]];
        [_headerView addSubview:bgImg];
        [_headerView sendSubviewToBack:bgImg];
        
        UIImageView *logoImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo"]];
        logoImage.contentMode = UIViewContentModeScaleAspectFit;
        [_headerView addSubview:logoImage];
        [logoImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(220.f), yAutoFit(37.f)));
            make.centerX.equalTo(self.headerView.mas_centerX);
            make.centerY.equalTo(self.headerView.mas_centerY);
        }];
        //切换登录/注册页面动画
        float spaWidth = 60;
        _loginBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(yAutoFit(45.f), yAutoFit(240.f), spaWidth, 40)];
        _loginBtn1.tag = 100;
        [_loginBtn1 setTitle:LocalString(@"登录") forState:UIControlStateNormal];
        [_loginBtn1.titleLabel setFont:[UIFont systemFontOfSize:20.f]];
        [_loginBtn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_loginBtn1 addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_loginBtn1];
        
        _registerBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(yAutoFit(45.f) + spaWidth, yAutoFit(240.f), spaWidth, 40)];
        _registerBtn1.tag = 200;
        [_registerBtn1 setTitle:LocalString(@"注册") forState:UIControlStateNormal];
        [_registerBtn1.titleLabel setFont:[UIFont systemFontOfSize:20.f]];
        [_registerBtn1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_registerBtn1 addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_registerBtn1];
        
        _forgetPWBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(yAutoFit(45.f), yAutoFit(240.f), spaWidth*2, 40)];
        [_forgetPWBtn1 setTitle:LocalString(@"忘记密码") forState:UIControlStateNormal];
        [_forgetPWBtn1.titleLabel setFont:[UIFont systemFontOfSize:20.f]];
        [_forgetPWBtn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.view addSubview:_forgetPWBtn1];
        _forgetPWBtn1.hidden = YES;
    }
    return _headerView;
}

-(UIView *)loginView{
    if (!_loginView) {
        _loginView = [[UIView alloc] initWithFrame:CGRectMake(0, yAutoFit(265.f), ScreenWidth, yAutoFit(380.f))];
        _loginView.backgroundColor = [UIColor clearColor];
        [self.view insertSubview:_loginView atIndex:0];
        /*........手机号输入........*/
        UIView *phoneview = [[UIView alloc] initWithFrame:CGRectMake(yAutoFit(45.f),yAutoFit(300.f),yAutoFit(284.f),yAutoFit(44.f))];
        phoneview.backgroundColor = [UIColor clearColor];
        //添加输入框下划线
        UIView * underLine = [[UIView alloc]initWithFrame:CGRectMake(0,phoneview.frame.size.height-2,phoneview.frame.size.width,1)];
        underLine.backgroundColor = [UIColor colorWithHexString:@"E6E6E6"];
        [_loginView addSubview:phoneview];
        [phoneview addSubview:underLine];
        
        [phoneview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), yAutoFit(44.f)));
            make.top.equalTo(self.view.mas_top).offset(yAutoFit(300.f));
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        _phoneLogTF = [[UITextField alloc] init];
        _phoneLogTF.backgroundColor = [UIColor clearColor];
        _phoneLogTF.font = [UIFont systemFontOfSize:15];
        _phoneLogTF.placeholder = LocalString(@"请输入手机号");
        _phoneLogTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _phoneLogTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _phoneLogTF.keyboardType = UIKeyboardTypePhonePad;
        _phoneLogTF.delegate = self;
        _phoneLogTF.borderStyle = UITextBorderStyleNone;
        [phoneview addSubview:_phoneLogTF];
        [_phoneLogTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(200.f),yAutoFit(30.f)));
            make.left.equalTo(phoneview.mas_left).offset(yAutoFit(55.f));
            make.centerY.equalTo(phoneview.mas_centerY);
        }];
        
        UIImageView *phoneleftImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"phone_image"]];
        phoneleftImage.contentMode = UIViewContentModeScaleAspectFit;
        [phoneview addSubview:phoneleftImage];
        [phoneleftImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(20.f), yAutoFit(20.f)));
            make.left.equalTo(phoneview.mas_left).offset(yAutoFit(18.f));
            make.centerY.equalTo(phoneview.mas_centerY);
        }];
        
        /*........密码输入........*/
        UIView *passwordLogTFView = [[UIView alloc] initWithFrame:CGRectMake(yAutoFit(45.f),yAutoFit(345.f),yAutoFit(284.f),yAutoFit(44.f))];
        passwordLogTFView.backgroundColor = [UIColor clearColor];
        //添加输入框下划线
        UIView * underLine2 = [[UIView alloc]initWithFrame:CGRectMake(0,passwordLogTFView.frame.size.height-2,passwordLogTFView.frame.size.width,1)];
        underLine2.backgroundColor = [UIColor colorWithHexString:@"E6E6E6"];
        [_loginView addSubview:passwordLogTFView];
        [passwordLogTFView addSubview:underLine2];
        
        [passwordLogTFView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), 44.f));
            make.top.equalTo(self.view.mas_top).offset(yAutoFit(345.f));
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        _passwordLogTF = [[UITextField alloc] init];
        _passwordLogTF.backgroundColor = [UIColor clearColor];
        _passwordLogTF.font = [UIFont systemFontOfSize:15];
        _passwordLogTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _passwordLogTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _passwordLogTF.delegate = self;
        _passwordLogTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _passwordLogTF.borderStyle = UITextBorderStyleNone;
        _passwordLogTF.placeholder = LocalString(@"请输入密码");
        _passwordLogTF.secureTextEntry = YES;
        [passwordLogTFView addSubview:_passwordLogTF];
        [_passwordLogTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(130.f),yAutoFit(30.f)));
            make.left.equalTo(passwordLogTFView.mas_left).offset(yAutoFit(55.f));
            make.centerY.equalTo(passwordLogTFView.mas_centerY);
        }];
        
        UIImageView *passwordleftImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"password_image"]];
        passwordleftImage.contentMode = UIViewContentModeScaleAspectFit;
        [passwordLogTFView addSubview:passwordleftImage];
        [passwordleftImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(20.f), yAutoFit(20.f)));
            make.left.equalTo(passwordLogTFView.mas_left).offset(yAutoFit(18.f));
            make.centerY.equalTo(passwordLogTFView.mas_centerY);
        }];
        
        /*........确认登录........*/
        _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loginBtn setTitle:LocalString(@"确定") forState:UIControlStateNormal];
        [_loginBtn.titleLabel setFont:[UIFont systemFontOfSize:17.f]];
        [_loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_loginBtn setBackgroundImage:[UIImage imageNamed:@"background_Btn_login"] forState:UIControlStateNormal];
        _loginBtn.contentMode = UIViewContentModeScaleAspectFit;
        [_loginBtn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
        _loginBtn.layer.cornerRadius = 3.f;
        _loginBtn.enabled = YES;
        [_loginView addSubview:_loginBtn];
        [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), 60));
            make.top.equalTo(passwordLogTFView.mas_bottom).offset(20.f);
            make.centerX.equalTo(self.loginView.mas_centerX);
        }];
        
        /*........忘记密码........*/
        _forgetPWBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_forgetPWBtn setTitle:LocalString(@"忘记密码?") forState:UIControlStateNormal];
        [_forgetPWBtn.titleLabel setFont:[UIFont systemFontOfSize:13.f]];
        [_forgetPWBtn setTitleColor:[UIColor colorWithHexString:@"4778CC"] forState:UIControlStateNormal];
        [_forgetPWBtn addTarget:self action:@selector(forgetPW) forControlEvents:UIControlEventTouchUpInside];
        [_loginView addSubview:_forgetPWBtn];
        [_forgetPWBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(100.f), yAutoFit(20.f)));
            make.centerX.equalTo(self.loginView.mas_centerX);
            make.top.equalTo(self.loginBtn.mas_bottom).offset(yAutoFit(10.f));
        }];
    }
    return _loginView;
}

-(UIView *)registerView{
    if (!_registerView) {
        _registerView = [[UIView alloc] initWithFrame:CGRectMake(0, yAutoFit(265.f), ScreenWidth, yAutoFit(380.f))];
        _registerView.backgroundColor = [UIColor clearColor];
        [self.view insertSubview:_registerView atIndex:0];
        /*........手机号........*/
        UIView *phoneview = [[UIView alloc] initWithFrame:CGRectMake(yAutoFit(45.f),yAutoFit(300.f),yAutoFit(284.f),yAutoFit(44.f))];
        phoneview.backgroundColor = [UIColor clearColor];
        //添加输入框下划线
        UIView * underLine = [[UIView alloc]initWithFrame:CGRectMake(0,phoneview.frame.size.height-2,phoneview.frame.size.width,1)];
        underLine.backgroundColor = [UIColor colorWithHexString:@"E6E6E6"];
        [_registerView addSubview:phoneview];
        [phoneview addSubview:underLine];
        
        [phoneview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), yAutoFit(44.f)));
            make.top.equalTo(self.view.mas_top).offset(yAutoFit(300.f));
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        _phoneRegTF = [[UITextField alloc] init];
        _phoneRegTF.backgroundColor = [UIColor clearColor];
        _phoneRegTF.font = [UIFont systemFontOfSize:15];
        _phoneRegTF.placeholder = LocalString(@"请输入手机号");
        _phoneRegTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _phoneRegTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _phoneRegTF.keyboardType = UIKeyboardTypePhonePad;
        _phoneRegTF.delegate = self;
        _phoneRegTF.borderStyle = UITextBorderStyleNone;
        [phoneview addSubview:_phoneRegTF];
        [_phoneRegTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(200.f),yAutoFit(30.f)));
            make.left.equalTo(phoneview.mas_left).offset(yAutoFit(55.f));
            make.centerY.equalTo(phoneview.mas_centerY);
        }];
        
        UIImageView *phoneleftImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"phone_image"]];
        phoneleftImage.contentMode = UIViewContentModeScaleAspectFit;
        [phoneview addSubview:phoneleftImage];
        [phoneleftImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(20.f), yAutoFit(20.f)));
            make.left.equalTo(phoneview.mas_left).offset(yAutoFit(18.f));
            make.centerY.equalTo(phoneview.mas_centerY);
        }];
        
        /*........验证码........*/
        UIView *verifyTFView = [[UIView alloc] initWithFrame:CGRectMake(yAutoFit(45.f),yAutoFit(345.f),yAutoFit(284.f),yAutoFit(44.f))];
        verifyTFView.backgroundColor = [UIColor clearColor];
        //添加输入框下划线
        UIView * underLine1 = [[UIView alloc]initWithFrame:CGRectMake(0,verifyTFView.frame.size.height-2,verifyTFView.frame.size.width,1)];
        underLine1.backgroundColor = [UIColor colorWithHexString:@"E6E6E6"];
        [_registerView insertSubview:verifyTFView atIndex:0];
        [verifyTFView addSubview:underLine1];
        
        [verifyTFView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), 44.f));
            make.top.equalTo(self.view.mas_top).offset(yAutoFit(345.f));
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        _verifyRegTF = [[UITextField alloc] init];
        _verifyRegTF.backgroundColor = [UIColor clearColor];
        _verifyRegTF.font = [UIFont systemFontOfSize:15];
        _verifyRegTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _verifyRegTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _verifyRegTF.delegate = self;
        _verifyRegTF.keyboardType = UIKeyboardTypePhonePad;
        _verifyRegTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _verifyRegTF.borderStyle = UITextBorderStyleNone;
        _verifyRegTF.placeholder = LocalString(@"请输入验证码");
        _verifyRegTF.secureTextEntry = NO;
        [verifyTFView addSubview:_verifyRegTF];
        [_verifyRegTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(130.f),yAutoFit(30.f)));
            make.left.equalTo(verifyTFView.mas_left).offset(yAutoFit(55.f));
            make.centerY.equalTo(verifyTFView.mas_centerY);
        }];
        
        UIImageView *verifyImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"verity_code"]];
        verifyImage.contentMode = UIViewContentModeScaleAspectFit;
        [verifyTFView addSubview:verifyImage];
        [verifyImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(20.f), yAutoFit(20.f)));
            make.left.equalTo(verifyTFView.mas_left).offset(yAutoFit(18.f));
            make.centerY.equalTo(verifyTFView.mas_centerY);
        }];
        
        _verifyRegBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_verifyRegBtn setTitle:LocalString(@"获取验证码") forState:UIControlStateNormal];
        [_verifyRegBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [_verifyRegBtn setTitleColor:[UIColor colorWithHexString:@"0465C5"] forState:UIControlStateNormal];
        _verifyRegBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
        [_verifyRegBtn addTarget:self action:@selector(getVerifyRegCode) forControlEvents:UIControlEventTouchUpInside];
        _verifyRegBtn.enabled = YES;
        [verifyTFView addSubview:_verifyRegBtn];
        [_verifyRegBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(80),yAutoFit(44.f)));
            make.right.equalTo(verifyTFView.mas_right);
            make.centerY.equalTo(verifyTFView.mas_centerY);
        }];
        
        /*........密码输入........*/
        UIView *passwordRegTFView = [[UIView alloc] initWithFrame:CGRectMake(yAutoFit(45.f),yAutoFit(390.f),yAutoFit(284.f),yAutoFit(44.f))];
        passwordRegTFView.backgroundColor = [UIColor clearColor];
        //添加输入框下划线
        UIView * underLine2 = [[UIView alloc]initWithFrame:CGRectMake(0,passwordRegTFView.frame.size.height-2,passwordRegTFView.frame.size.width,1)];
        underLine2.backgroundColor = [UIColor colorWithHexString:@"E6E6E6"];
        [_registerView insertSubview:passwordRegTFView atIndex:0];
        [passwordRegTFView addSubview:underLine2];
        
        [passwordRegTFView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), 44.f));
            make.top.equalTo(self.view.mas_top).offset(yAutoFit(390.f));
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        _passwordRegTF = [[UITextField alloc] init];
        _passwordRegTF.backgroundColor = [UIColor clearColor];
        _passwordRegTF.font = [UIFont systemFontOfSize:15];
        _passwordRegTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _passwordRegTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _passwordRegTF.delegate = self;
        _passwordRegTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _passwordRegTF.borderStyle = UITextBorderStyleNone;
        _passwordRegTF.placeholder = LocalString(@"请输入密码（6位以上字符）");
        _passwordRegTF.secureTextEntry = YES;
        [passwordRegTFView addSubview:_passwordRegTF];
        [_passwordRegTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(200.f),yAutoFit(30.f)));
            make.left.equalTo(passwordRegTFView.mas_left).offset(yAutoFit(55.f));
            make.centerY.equalTo(passwordRegTFView.mas_centerY);
        }];
        
        UIImageView *passwordleftImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"password_image"]];
        passwordleftImage.contentMode = UIViewContentModeScaleAspectFit;
        [passwordRegTFView addSubview:passwordleftImage];
        [passwordleftImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(20.f), yAutoFit(20.f)));
            make.left.equalTo(passwordRegTFView.mas_left).offset(yAutoFit(18.f));
            make.centerY.equalTo(passwordRegTFView.mas_centerY);
        }];
        
        /*........密码重复输入........*/
        UIView *passwordConTFView = [[UIView alloc] initWithFrame:CGRectMake(yAutoFit(45.f),yAutoFit(435.f),yAutoFit(284.f),yAutoFit(44.f))];
        passwordConTFView.backgroundColor = [UIColor clearColor];
        //添加输入框下划线
        UIView * underLine3 = [[UIView alloc]initWithFrame:CGRectMake(0,passwordConTFView.frame.size.height-2,passwordConTFView.frame.size.width,1)];
        underLine3.backgroundColor = [UIColor colorWithHexString:@"E6E6E6"];
        [_registerView insertSubview:passwordConTFView atIndex:0];
        [passwordConTFView addSubview:underLine3];
        
        [passwordConTFView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), 44.f));
            make.top.equalTo(self.view.mas_top).offset(yAutoFit(435.f));
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        _passwordRegConTF = [[UITextField alloc] init];
        _passwordRegConTF.backgroundColor = [UIColor clearColor];
        _passwordRegConTF.font = [UIFont systemFontOfSize:15];
        _passwordRegConTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _passwordRegConTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _passwordRegConTF.delegate = self;
        _passwordRegConTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _passwordRegConTF.borderStyle = UITextBorderStyleNone;
        _passwordRegConTF.placeholder = LocalString(@"请再次确认输入密码");
        _passwordRegConTF.secureTextEntry = YES;
        [passwordConTFView addSubview:_passwordRegConTF];
        [_passwordRegConTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(160.f),yAutoFit(30.f)));
            make.left.equalTo(passwordConTFView.mas_left).offset(yAutoFit(55.f));
            make.centerY.equalTo(passwordConTFView.mas_centerY);
        }];
        
        UIImageView *passwordleftImage1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"password_image"]];
        passwordleftImage1.contentMode = UIViewContentModeScaleAspectFit;
        [passwordConTFView addSubview:passwordleftImage1];
        [passwordleftImage1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(20.f), yAutoFit(20.f)));
            make.left.equalTo(passwordConTFView.mas_left).offset(yAutoFit(18.f));
            make.centerY.equalTo(passwordConTFView.mas_centerY);
        }];
        
        /*........确认注册........*/
        _registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_registerBtn setTitle:LocalString(@"确定") forState:UIControlStateNormal];
        [_registerBtn.titleLabel setFont:[UIFont systemFontOfSize:17.f]];
        [_registerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_registerBtn setBackgroundImage:[UIImage imageNamed:@"background_Btn_login"] forState:UIControlStateNormal];
        _registerBtn.contentMode = UIViewContentModeScaleAspectFit;
        [_registerBtn addTarget:self action:@selector(registerGo) forControlEvents:UIControlEventTouchUpInside];
        _registerBtn.layer.cornerRadius = 3.f;
        _registerBtn.enabled = YES;
        [_registerView addSubview:_registerBtn];
        [_registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), 60));
            make.top.equalTo(self.passwordRegConTF.mas_bottom).offset(yAutoFit(20.f));
            make.centerX.equalTo(self.registerView.mas_centerX);
        }];
        
        _registerView.hidden = YES;
    }
    return _registerView;
}

-(UIView *)forgetPWView{
    if (!_forgetPWView) {
        _forgetPWView = [[UIView alloc] initWithFrame:CGRectMake(0, yAutoFit(265.f), ScreenWidth, yAutoFit(380.f))];
        _forgetPWView.backgroundColor = [UIColor clearColor];
        [self.view insertSubview:_forgetPWView atIndex:0];
        /*........手机号........*/
        UIView *phoneview = [[UIView alloc] initWithFrame:CGRectMake(yAutoFit(45.f),yAutoFit(300.f),yAutoFit(284.f),yAutoFit(44.f))];
        phoneview.backgroundColor = [UIColor clearColor];
        //添加输入框下划线
        UIView * underLine = [[UIView alloc]initWithFrame:CGRectMake(0,phoneview.frame.size.height-2,phoneview.frame.size.width,1)];
        underLine.backgroundColor = [UIColor colorWithHexString:@"E6E6E6"];
        [_forgetPWView addSubview:phoneview];
        [phoneview addSubview:underLine];
        
        [phoneview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), yAutoFit(44.f)));
            make.top.equalTo(self.view.mas_top).offset(yAutoFit(300.f));
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        _phoneTF = [[UITextField alloc] init];
        _phoneTF.backgroundColor = [UIColor clearColor];
        _phoneTF.font = [UIFont systemFontOfSize:15];
        _phoneTF.placeholder = LocalString(@"请输入手机号");
        _phoneTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _phoneTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _phoneTF.keyboardType = UIKeyboardTypePhonePad;
        _phoneTF.delegate = self;
        _phoneTF.borderStyle = UITextBorderStyleNone;
        [phoneview addSubview:_phoneTF];
        [_phoneTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(200.f),yAutoFit(30.f)));
            make.left.equalTo(phoneview.mas_left).offset(yAutoFit(55.f));
            make.centerY.equalTo(phoneview.mas_centerY);
        }];
        
        UIImageView *phoneleftImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"phone_image"]];
        phoneleftImage.contentMode = UIViewContentModeScaleAspectFit;
        [phoneview addSubview:phoneleftImage];
        [phoneleftImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(20.f), yAutoFit(20.f)));
            make.left.equalTo(phoneview.mas_left).offset(yAutoFit(18.f));
            make.centerY.equalTo(phoneview.mas_centerY);
        }];
        
        /*........验证码........*/
        UIView *verifyTFView = [[UIView alloc] initWithFrame:CGRectMake(yAutoFit(45.f),yAutoFit(345.f),yAutoFit(284.f),yAutoFit(44.f))];
        verifyTFView.backgroundColor = [UIColor clearColor];
        //添加输入框下划线
        UIView * underLine1 = [[UIView alloc]initWithFrame:CGRectMake(0,verifyTFView.frame.size.height-2,verifyTFView.frame.size.width,1)];
        underLine1.backgroundColor = [UIColor colorWithHexString:@"E6E6E6"];
        [_forgetPWView insertSubview:verifyTFView atIndex:0];
        [verifyTFView addSubview:underLine1];
        
        [verifyTFView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), yAutoFit(44.f)));
            make.top.equalTo(self.view.mas_top).offset(yAutoFit(345.f));
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        _verifyTF = [[UITextField alloc] init];
        _verifyTF.backgroundColor = [UIColor clearColor];
        _verifyTF.font = [UIFont systemFontOfSize:15];
        _verifyTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _verifyTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _verifyTF.delegate = self;
        _verifyTF.keyboardType = UIKeyboardTypePhonePad;
        _verifyTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _verifyTF.borderStyle = UITextBorderStyleNone;
        _verifyTF.placeholder = LocalString(@"请输入验证码");
        _verifyTF.secureTextEntry = NO;
        [verifyTFView addSubview:_verifyTF];
        [_verifyTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(130.f),yAutoFit(30.f)));
            make.left.equalTo(verifyTFView.mas_left).offset(yAutoFit(55.f));
            make.centerY.equalTo(verifyTFView.mas_centerY);
        }];
        
        UIImageView *verifyImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"verity_code"]];
        verifyImage.contentMode = UIViewContentModeScaleAspectFit;
        [verifyTFView addSubview:verifyImage];
        [verifyImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(20.f), yAutoFit(20.f)));
            make.left.equalTo(verifyTFView.mas_left).offset(yAutoFit(18.f));
            make.centerY.equalTo(verifyTFView.mas_centerY);
        }];
        
        _verifyforgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_verifyforgetBtn setTitle:LocalString(@"获取验证码") forState:UIControlStateNormal];
        [_verifyforgetBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
        [_verifyforgetBtn setTitleColor:[UIColor colorWithHexString:@"0465C5"] forState:UIControlStateNormal];
        _verifyforgetBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
        [_verifyforgetBtn addTarget:self action:@selector(getVerifyCode) forControlEvents:UIControlEventTouchUpInside];
        _verifyforgetBtn.enabled = YES;
        [verifyTFView addSubview:_verifyforgetBtn];
        [_verifyforgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(80),yAutoFit(44.f)));
            make.right.equalTo(verifyTFView.mas_right);
            make.centerY.equalTo(verifyTFView.mas_centerY);
        }];
        
        /*........密码输入........*/
        UIView *passwordRegTFView = [[UIView alloc] initWithFrame:CGRectMake(yAutoFit(45.f),yAutoFit(390.f),yAutoFit(284.f),yAutoFit(44.f))];
        passwordRegTFView.backgroundColor = [UIColor clearColor];
        //添加输入框下划线
        UIView * underLine2 = [[UIView alloc]initWithFrame:CGRectMake(0,passwordRegTFView.frame.size.height-2,passwordRegTFView.frame.size.width,1)];
        underLine2.backgroundColor = [UIColor colorWithHexString:@"E6E6E6"];
        [_forgetPWView insertSubview:passwordRegTFView atIndex:0];
        [passwordRegTFView addSubview:underLine2];
        
        [passwordRegTFView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), 44.f));
            make.top.equalTo(self.view.mas_top).offset(yAutoFit(390.f));
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        _forgetPWTF = [[UITextField alloc] init];
        _forgetPWTF.backgroundColor = [UIColor clearColor];
        _forgetPWTF.font = [UIFont systemFontOfSize:15];
        _forgetPWTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _forgetPWTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _forgetPWTF.delegate = self;
        _forgetPWTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _forgetPWTF.borderStyle = UITextBorderStyleNone;
        _forgetPWTF.placeholder = LocalString(@"请输入密码（6位以上字符）");
        _forgetPWTF.secureTextEntry = YES;
        [passwordRegTFView addSubview:_forgetPWTF];
        [_forgetPWTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(200.f),yAutoFit(30.f)));
            make.left.equalTo(passwordRegTFView.mas_left).offset(yAutoFit(55.f));
            make.centerY.equalTo(passwordRegTFView.mas_centerY);
        }];
        
        UIImageView *passwordleftImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"password_image"]];
        passwordleftImage.contentMode = UIViewContentModeScaleAspectFit;
        [passwordRegTFView addSubview:passwordleftImage];
        [passwordleftImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(20.f), yAutoFit(20.f)));
            make.left.equalTo(passwordRegTFView.mas_left).offset(yAutoFit(18.f));
            make.centerY.equalTo(passwordRegTFView.mas_centerY);
        }];
        
        /*........密码重复输入........*/
        UIView *passwordConTFView = [[UIView alloc] initWithFrame:CGRectMake(yAutoFit(45.f),yAutoFit(435.f),yAutoFit(284.f),yAutoFit(44.f))];
        passwordConTFView.backgroundColor = [UIColor clearColor];
        //添加输入框下划线
        UIView * underLine3 = [[UIView alloc]initWithFrame:CGRectMake(0,passwordConTFView.frame.size.height-2,passwordConTFView.frame.size.width,1)];
        underLine3.backgroundColor = [UIColor colorWithHexString:@"E6E6E6"];
        [_forgetPWView insertSubview:passwordConTFView atIndex:0];
        [passwordConTFView addSubview:underLine3];
        
        [passwordConTFView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), yAutoFit(44.f)));
            make.top.equalTo(self.view.mas_top).offset(yAutoFit(435.f));
            make.centerX.equalTo(self.view.mas_centerX);
        }];
        
        _passwordConTF = [[UITextField alloc] init];
        _passwordConTF.backgroundColor = [UIColor clearColor];
        _passwordConTF.font = [UIFont systemFontOfSize:15];
        _passwordConTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _passwordConTF.autocorrectionType = UITextAutocorrectionTypeNo;
        _passwordConTF.delegate = self;
        _passwordConTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _passwordConTF.borderStyle = UITextBorderStyleNone;
        _passwordConTF.placeholder = LocalString(@"请再次确认输入密码");
        _passwordConTF.secureTextEntry = YES;
        [passwordConTFView addSubview:_passwordConTF];
        [_passwordConTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(160.f),yAutoFit(30.f)));
            make.left.equalTo(passwordConTFView.mas_left).offset(yAutoFit(55.f));
            make.centerY.equalTo(passwordConTFView.mas_centerY);
        }];
        
        UIImageView *passwordleftImage1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"password_image"]];
        passwordleftImage1.contentMode = UIViewContentModeScaleAspectFit;
        [passwordConTFView addSubview:passwordleftImage1];
        [passwordleftImage1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(20.f), yAutoFit(20.f)));
            make.left.equalTo(passwordConTFView.mas_left).offset(yAutoFit(18.f));
            make.centerY.equalTo(passwordConTFView.mas_centerY);
        }];
        
        /*........确认修改密码........*/
        _forgetSureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_forgetSureBtn setTitle:LocalString(@"确定") forState:UIControlStateNormal];
        [_forgetSureBtn.titleLabel setFont:[UIFont systemFontOfSize:17.f]];
        [_forgetSureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_forgetSureBtn setBackgroundImage:[UIImage imageNamed:@"background_Btn_login"] forState:UIControlStateNormal];
        _forgetSureBtn.contentMode = UIViewContentModeScaleAspectFit;
        [_forgetSureBtn addTarget:self action:@selector(forgetSure) forControlEvents:UIControlEventTouchUpInside];
        _forgetSureBtn.layer.cornerRadius = 3.f;
        _forgetSureBtn.enabled = YES;
        [_forgetPWView addSubview:_forgetSureBtn];
        [_forgetSureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), 60));
            make.top.equalTo(passwordConTFView.mas_bottom).offset(yAutoFit(20.f));
            make.centerX.equalTo(self.forgetPWView.mas_centerX);
        }];
        
        _forgetBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_forgetBackBtn setTitle:LocalString(@"返回") forState:UIControlStateNormal];
        [_forgetBackBtn.titleLabel setFont:[UIFont systemFontOfSize:17.f]];
        [_forgetBackBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_forgetBackBtn setBackgroundImage:[UIImage imageNamed:@"background_Btn_login"] forState:UIControlStateNormal];
        _forgetBackBtn.contentMode = UIViewContentModeScaleAspectFit;
        [_forgetBackBtn addTarget:self action:@selector(forgetBack) forControlEvents:UIControlEventTouchUpInside];
        _forgetBackBtn.layer.cornerRadius = 3.f;
        _forgetBackBtn.enabled = YES;
        [_forgetPWView addSubview:_forgetBackBtn];
        [_forgetBackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(yAutoFit(284.f), 60));
            make.top.equalTo(self.forgetSureBtn.mas_bottom).offset(yAutoFit(10.f));
            make.centerX.equalTo(self.forgetPWView.mas_centerX);
        }];
        
        _forgetPWView.hidden = YES;
    }
    return _forgetPWView;
}

#pragma mark - uitextfield delegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
    
}

#pragma mark - Giz回调

// 登录回调
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didUserLogin:(NSError *)result uid:(NSString *)uid token:(NSString *)token {
    if(result.code == GIZ_SDK_SUCCESS) {
        // 登录成功
        [GizManage shareInstance].uid = uid;
        [GizManage shareInstance].token = token;
        [GizManage shareInstance].userPhone = self.phoneLogTF.text;
        //保存帐号密码
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        [userDefaults setObject:self.phoneLogTF.text forKey:@"mobile"];
        [userDefaults setObject:self.passwordLogTF.text forKey:@"password"];
        
        [userDefaults synchronize];
        
        MainViewController *mainVC = [[MainViewController alloc] init];
        [self presentViewController:mainVC animated:YES completion:nil];
        
    } else {
        // 登录失败
        [NSObject showHudTipStr:LocalString(@"手机号或密码不正确")];
    }
}
// 注册回调
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didRegisterUser:(NSError *)result uid:(NSString *)uid token:(NSString *)token {
    if(result.code == GIZ_SDK_SUCCESS) {
        // 注册成功
        NSLog(@"注册成功");
        [NSObject showHudTipStr:LocalString(@"注册成功")];
        MyDeviceViewController *myDeviceVC = [[MyDeviceViewController alloc] init];
        [self.navigationController pushViewController:myDeviceVC animated:YES];
        
    } else {
        // 注册失败
        [NSObject showHudTipStr:LocalString(@"注册失败")];
        NSLog(@"注册失败%@",result);
        //[NSObject showHudTipStr3:[NSString stringWithFormat:@"%@",result]];
    }
    
}
// 忘记密码回调
- (void)wifiSDK:(GizWifiSDK *)wifiSDK didChangeUserPassword:(NSError *)result {
    if(result.code == GIZ_SDK_SUCCESS) {
        // 修改成功
        [NSObject showHudTipStr:@"修改密码成功"];
        [self dismissViewControllerAnimated:YES completion:nil];
    } else {
        // 修改失败
        [NSObject showHudTipStr:@"修改密码失败"];
    }
}

#pragma mark - Actions

//加载用户信息
- (void)loadUserInfo{
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *mobile = [userDefaults objectForKey:@"mobile"];
    NSString *password = [userDefaults objectForKey:@"password"];
    self.phoneLogTF.text = mobile;
    self.passwordLogTF.text = password;
}

- (void)login{
    if (![NSString validateMobile:self.phoneLogTF.text] || self.passwordLogTF.text.length < 6){
        [NSObject showHudTipStr:LocalString(@"手机号或密码长度不正确")];
        return;
    }else{
        [SVProgressHUD dismiss];
        [[GizWifiSDK sharedInstance] userLogin:self.phoneLogTF.text password:self.passwordLogTF.text];
        NSLog(@"账号%@ 密码%@",self.phoneLogTF.text,_passwordLogTF.text);
    }
}

- (void)registerGo{
    if ([NSString validateMobile:_phoneRegTF.text] && _verifyRegTF.text.length == 6 && _passwordRegTF.text.length >= 6 && [_passwordRegTF.text isEqualToString:_passwordRegConTF.text]){
        [[GizWifiSDK sharedInstance] registerUser:_phoneRegTF.text password:_passwordRegTF.text verifyCode:_verifyRegTF.text accountType:GizUserPhone];
    }else{
        [NSObject showHudTipStr:LocalString(@"注册用户失败，请检查您填写的信息")];
        return;
    }
}

- (void)autoLogin{
    [SVProgressHUD show];
    
    [self loadUserInfo];
    
    if (![NSString validateMobile:self.phoneLogTF.text] || self.passwordLogTF.text.length < 6){
        [NSObject showHudTipStr:LocalString(@"自动登录失败")];
        [SVProgressHUD dismiss];
        return;
    }
    [self login];
    
}

- (void)onClick:(UIButton *)sender{
    
    _loginBtn1 = (UIButton *)[self.view viewWithTag:100];
    _registerBtn1 = (UIButton *)[self.view viewWithTag:200];
    if (sender.tag == 100) {
        
        [_loginBtn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_registerBtn1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        
        _loginView.hidden = NO;
        _registerView.hidden = YES;
        
    }else{
        
        [_loginBtn1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_registerBtn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _loginView.hidden = YES;
        _registerView.hidden = NO;
    }
}

//- (void)passwordVisiableControl{
//    if (_passwordVisiableBtn.tag == yUnselect) {
//        _passwordVisiableBtn.tag = ySelect;
//        [_passwordVisiableBtn setImage:[UIImage imageNamed:@"img_pwd_visiable"] forState:UIControlStateNormal];
//        _passwordLogTF.secureTextEntry = NO;
//    }else{
//        _passwordVisiableBtn.tag = yUnselect;
//        [_passwordVisiableBtn setImage:[UIImage imageNamed:@"img_pwd_unvisiable"] forState:UIControlStateNormal];
//        _passwordLogTF.secureTextEntry = YES;
//    }
//}

- (void)forgetPW{
    _loginBtn1.hidden =YES;
    _registerBtn1.hidden = YES;
    _forgetPWBtn.hidden = YES;
    _forgetPWBtn1.hidden = NO;
    _loginView.hidden = YES;
    _registerView.hidden = YES;
    _forgetPWView.hidden = NO;
}

-(void)forgetSure{
    
    if ([NSString validateMobile:_phoneTF.text] && _verifyTF.text.length == 6 && _forgetPWTF.text.length >= 6 && [_forgetPWTF.text isEqualToString:_passwordConTF.text]) {
        
        [self modifyPassword];
    }else if(!([NSString validateMobile:_phoneTF.text])) {
        [NSObject showHudTipStr:@"手机号格式错误"];
    }else if (!(self.verifyTF.text.length == 6)){
        [NSObject showHudTipStr:@"请输入6位验证码"];
    }else if (!(self.forgetPWTF.text.length >= 6 && self.passwordConTF.text.length >= 6)){
        [NSObject showHudTipStr:@"密码不少于6位"];
    }else if (![self.forgetPWTF.text isEqualToString:self.passwordConTF.text]){
        [NSObject showHudTipStr:@"两次密码输入不同"];
    }else{
        [NSObject showHudTipStr:@"输入信息有误"];
    }
    
}

- (void)forgetBack{
    _loginBtn1.hidden =NO;
    _registerBtn1.hidden = NO;
    _forgetPWBtn.hidden = NO;
    _forgetPWBtn1.hidden = YES;
    _loginView.hidden = NO;
    _registerView.hidden = YES;
    _forgetPWView.hidden = YES;
}

- (void)modifyPassword{
    
    [[GizWifiSDK sharedInstance] resetPassword:self.phoneTF.text verifyCode:self.verifyTF.text newPassword:self.passwordConTF.text accountType:GizUserPhone];
}

//获取验证码
- (void)getVerifyCode{
    
    if ([NSString validateMobile:_phoneTF.text]){
        [self openCountdown];
        [[GizWifiSDK sharedInstance] requestSendPhoneSMSCode:GizAppSecret phone:self.phoneTF.text];
    }else {
        [NSObject showHudTipStr:LocalString(@"手机号码不正确")];
    }
}

//获取验证码
- (void)getVerifyRegCode{
    
    if ([NSString validateMobile:_phoneRegTF.text]){
        [self openCountdownReg];
        [[GizWifiSDK sharedInstance] requestSendPhoneSMSCode:GizAppSecret phone:self.phoneRegTF.text];
    }else {
        [NSObject showHudTipStr:LocalString(@"手机号码不正确")];
    }
}
//开始倒计时
-(void)openCountdown{
    
    __block NSInteger time = 59; //倒计时时间
    
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
    
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
        
        if(time <= 0){ //倒计时结束，关闭
            
            dispatch_source_cancel(self.timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //设置按钮的样式
                [self.verifyforgetBtn setTitle:@"重新发送" forState:UIControlStateNormal];
                self.verifyforgetBtn.userInteractionEnabled = YES;
            });
            
        }else{
            
            int seconds = time % 60;
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //设置按钮显示读秒效果
                [self.verifyforgetBtn setTitle:[NSString stringWithFormat:@"%2ds", seconds] forState:UIControlStateNormal];
                self.verifyforgetBtn.userInteractionEnabled = NO;
            });
            time--;
        }
    });
    dispatch_resume(_timer);
}

-(void)openCountdownReg{
    
    __block NSInteger time = 59; //倒计时时间
    
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
    
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
        
        if(time <= 0){ //倒计时结束，关闭
            
            dispatch_source_cancel(self.timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //设置按钮的样式
                [self.verifyRegBtn setTitle:@"重新发送" forState:UIControlStateNormal];
                self.verifyRegBtn.userInteractionEnabled = YES;
            });
            
        }else{
            
            int seconds = time % 60;
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //设置按钮显示读秒效果
                [self.verifyRegBtn setTitle:[NSString stringWithFormat:@"%2ds", seconds] forState:UIControlStateNormal];
                self.verifyRegBtn.userInteractionEnabled = NO;
            });
            time--;
        }
    });
    dispatch_resume(_timer);
}

@end
